package ace.j2se.l3;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * @author Aceguan
 * @description 反射概念1
 * @date 2012-2-26 下午06:13:27
 * @version v1.0
 */
public class ReflectTest {
	public static void main(String[] args) throws ClassNotFoundException,
			SecurityException, NoSuchMethodException, IllegalArgumentException,
			IllegalAccessException, InvocationTargetException {
		ReflectTest r = new ReflectTest();
		// 显示包与类名
		System.out.println(ReflectTest.class.getName());
		Class c = Class.forName(ReflectTest.class.getName());
		// 类对象的所有public方法
		System.out.println(c.getMethods().length);
		// 寻找名字为test的公开方法
		Method method = c.getMethod("test", null);
		// 让对象执行方法
		method.invoke(r, null);
	}

	public void test() {
		System.out.println("This is test method!");
	}
}
